package com.jy.it.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

//@Repository
//@Service
//@Controller

@Component
public class EmailUtil {
	@Autowired
	private JavaMailSender sender;//发送邮件的组件，从spring容器里面拿进来
	
	public void sendMail(String to,String subject,String content) {
		SimpleMailMessage msg=new SimpleMailMessage();//邮件的消息对象
		msg.setTo(to);
		msg.setFrom("wfccpa@qq.com");//和配置文件里的一致
		msg.setSubject(subject);//标题
		msg.setText(content);//邮件的内容
		sender.send(msg);//发送
		System.out.println("发送邮件成功");
	}
	
	public static void main(String[] args) {
		ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext-mail.xml");
		EmailUtil emailUtil=cxt.getBean(EmailUtil.class);
		emailUtil.sendMail("2897645188@qq.com", "你好，很久不见", "雷兆杰早上好");
		
	}
}
